package com.ecoolex.cms.system.api.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecoolex.cms.system.entity.SunrisedutyfreeApplication;
import com.ecoolex.cms.system.pojo.CouponDTO;
import com.ecoolex.cms.system.ws.CmsSystemService;
import com.ecoolex.framework.common.annotation.MethodCatchException;
import com.ecoolex.framework.common.pojo.BizResult;
import com.ecoolex.framework.common.util.Assert;
import com.ecoolex.framework.common.util.Check;


@RestController
@RequestMapping("/coupon")
public class CouponController {

	@Reference
	private CmsSystemService cmsSystemService;

	@PostMapping("/get")
	@MethodCatchException
	public BizResult<CouponDTO> getToken(String token) {
		Assert.isTrue(Check.notNullOrTrimEmpty(token), 103, "Token不存在");
		SunrisedutyfreeApplication application = cmsSystemService.getSunrisedutyfreeApplicationByToken(token);
		Assert.isTrue(Check.notNull(application), 201, "Token失效");
		BizResult<CouponDTO> result = cmsSystemService.getCouponDTOBarcode(application.getToken());
		return result.isSuccessful() ? result
			: BizResult.create().setFailed("获取优惠券失败");
	}
}
